package muslim30;

import java.io.IOException;
import java.util.LinkedList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class DailyServlet
 */
public class DailyServlet extends HttpServlet {
	
	
	
	private static final long serialVersionUID = 1L;
    
	
	private final LinkedList<String> URLList = new LinkedList<String>() {
		
		/**
		 * 
		 */
		private static final long serialVersionUID = -2793680731103078060L;

		{
			add("/WEB-INF/daily/2013_1.html");
			add("/WEB-INF/daily/2013_2.html");
			add("/WEB-INF/daily/2013_3.html");
			add("/WEB-INF/daily/2013_4.html");
			add("/WEB-INF/daily/2013_5.html");
			add("/WEB-INF/daily/2013_6.html");
			add("/WEB-INF/daily/2013_7.html");
			add("/WEB-INF/daily/2013_8.html");
			add("/WEB-INF/daily/2013_9.html");
			add("/WEB-INF/daily/2013_10.html");
			add("/WEB-INF/daily/2013_11.html");
			add("/WEB-INF/daily/2013_12.html");
			add("/WEB-INF/daily/2013_13.html");
			add("/WEB-INF/daily/2013_14.html");
			add("/WEB-INF/daily/2013_15.html");
			add("/WEB-INF/daily/2013_16.html");
			add("/WEB-INF/daily/2013_17.html");
			add("/WEB-INF/daily/2013_18.html");
			add("/WEB-INF/daily/2013_19.html");
			add("/WEB-INF/daily/2013_20.html");
			add("/WEB-INF/daily/2013_21.html");
			add("/WEB-INF/daily/2013_22.html");
			add("/WEB-INF/daily/2013_23.html");
			add("/WEB-INF/daily/2013_24.html");
			add("/WEB-INF/daily/2013_25.html");
			add("/WEB-INF/daily/2013_26.html");
			add("/WEB-INF/daily/2013_27.html");
			add("/WEB-INF/daily/2013_28.html");
			add("/WEB-INF/daily/2013_29.html");
			add("/WEB-INF/daily/2013_30.html");
			
		}
	};
	
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DailyServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		DateChecker checker = new DateChecker();
		
		int diff = checker.getDiff();
		
		String url = null;
		
		if(diff < 0) {
			url = "/WEB-INF/daily/2013_1.html";
		} else if(diff >= 0 && diff < 30) {
			url = URLList.get(diff);
		} else {
			
		}
		
		RequestDispatcher rd =
				  request.getRequestDispatcher(url);
		rd.forward(request, response);
	}

}
